<template>
	<view class="mobilephoneLogin">
		<u-navbar back-icon-color="#000" :back-text-style="{color: '#000'}" :back-text="this.from=='forget'?'忘记密码':'手机号注册'" />
		<view class="content">
			<view class="tips">请设置登录密码，8-20位字符，至少包含字符/数字/符号2种组合</view>
			<view class="inputs">
				<input type="password" v-model="password" />
				<uni-icons v-show="password" @click="password = ''" style="transform: translateY(20%);" type="closeempty" color="#ccc"
				 size="15"></uni-icons>
			</view>
			<commonBtn :title="loginBtn.title" :style="{ backgroundColor: !password ? '#72bfc4' : '#07a0aa' }" @click="jumpToNext"></commonBtn>
		</view>
	</view>
</template>

<script>
	import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
	import uniIcons from '@/components/uni-icons/uni-icons.vue';
	import commonBtn from '@/components/commonBtn/commonBtn.vue';
	import {
		sentCaptcha
	} from '@/api/captcha.js';
	export default {
		data() {
			return {
				password: '',
				phone: '',
				countrycode: '',
				from: '',
				loginBtn: {
					title: '下一步',
					permission: true
				}
			};
		},
		onLoad(e) {
			this.phone = e.phone;
			this.countrycode = e.countryCode;
			this.from = e.from;
			this.captcha = e.captcha
		},
		methods: {
			jumpToNext() {
				if (!(this.password.length >= 8 && this.password.length <= 20)) {
					uni.showToast({
						title: '需8-20位字符',
						icon: 'none'
					});
				} else if (!this.$twoTypeReg.test(this.password)) {
					uni.showToast({
						title: '需字母/数字/字符中两种以上组合',
						icon: 'none'
					});
				} else {
					if (this.from == 'forget') {
						uni.showLoading();
						sentCaptcha({
								phone: this.phone,
								ctcode: this.countrycode
							})
							.then(res => {
								uni.hideLoading();
								if (res.code == 200) {
									uni.navigateTo({
										url: '/pages/login/mobilephoneLogin/inputCaptcha?phone=' + this.phone + '&password=' + this.password +
											'&from=forget&countryCode=' + this.countrycode
									});
								} else {
									uni.showToast({
										title: res.message || res.msg,
										icon: 'none'
									});
								}
							})
							.catch(err => {
								uni.hideLoading();
								uni.showToast({
									title: '发送失败',
									icon: 'none'
								});
							});
					} else if (this.from == "register") {
						uni.navigateTo({
							url: "/pages/login/mobilephoneLogin/inputNickname?captcha=" + this.captcha + "&password=" + this.password +
								"&phone=" + this.phone
						})
					}
				}
			}
		},
		components: {
			components: {
				uniNavBar,
				uniIcons,
				commonBtn
			}
		}
	};
</script>

<style lang="scss">
	.mobilephoneLogin {
		/deep/.uni-navbar--border {
			border: none;
		}

		.content {
			padding: 20px;
			box-sizing: border-box;

			.tips {
				color: #ccc;
				font-size: 12px;
				margin-top: 6px;
			}

			.inputs {
				display: flex;
				align-items: center;
				width: 100%;
				height: 46px;
				border-bottom: 1px #ccc solid;
				padding-top: 22px;
				padding-right: 2px;
				margin-bottom: 22px;

				>input {
					flex: 1;
					height: 100%;
					font-size: 16px;
				}
			}
		}
	}
</style>
